# -*- coding: utf-8 -*-
"""
@Time： 2023/12/20 16:20
@Auth： gubei
@File：views.py
@IDE：PyCharm
@Description：
"""

from fastapi import APIRouter, Query, Depends
from sqlalchemy import func
from sqlalchemy.orm import Session

from core.db.database import get_db
from core.models.models import Logs
from utils.response import *

router = APIRouter()


@router.get("s", summary='获取日志列表')
async def get_logs(page: int = Query(1, alias="page"), pagesize: int = Query(10), db: Session = Depends(get_db)):
    logs = db.query(Logs).filter().offset(page - 1).limit(pagesize).all()
    total = db.query(func.count(Logs.id)).scalar()
    return R.suc(data=[i.to_dict() for i in logs], total=total)

